import { func } from "prop-types";
import React from "react";


// 约定高阶组件函数的名字以with开头

function withMove(Component){
    class Move extends React.Component{
        // 状态数据
    state={ 
        x:0,
        y:0
    }
    // 修改数据的方法
    getMove=(e)=>{
        this.setState({
            x:e.clientX,
            y:e.clientY
        })
    }
    render(){
        console.log("move",this.props)
        return <Component {...this.state} {...this.props}></Component>
    }
    componentDidMount(){
        window.addEventListener("mousemove",this.getMove)
    }
    componentWillUnmount(){
        window.removeEventListener("mousemove",this.getMove)
    }
}

    return Move

}

export default withMove

